package com.doudou.oauth.config;

import com.doudou.oauth.constant.SysConstant;
import com.doudou.oauth.handler.FailLoginHandler;
import com.doudou.oauth.handler.SuccessLoginHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @Author: 傻男人
 * @Date: 2020/5/8 15:50
 * @Version: 1.0
 * @Description:  最基本的表单登录配置
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    protected SuccessLoginHandler successLoginHandler;

    @Autowired
    protected FailLoginHandler failLoginHandler;

    protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SysConstant.DEFAULT_UNAUTHENTICATION_URL)
                .loginProcessingUrl(SysConstant.DEFAULT_LOGIN_PROCESSING_URL_FORM)
                .successHandler(successLoginHandler)
                .failureHandler(failLoginHandler);
    }
}
